﻿/*
大数加 
Time Limit:1000MS  Memory Limit:32768K


Description:
给定一些大数，请计算其和。

Input:
输入数据中含有一些数据组（数量≤100），每组数据由一个整数n（n≤100）领衔，
后跟n个大整数（0≤大数，大数位数≤200），若n＝0则表示输入结束。 
Output:
输出每组数据所计算的大数和，每个结果单独占一行。 
Sample Input:
5
123456789
6287999980
5645645654654
5
79
0
Sample Output:
5652057111507
*/
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	for (unsigned n; cin >> n && n;)
	{
		string bignum;
		cin >> bignum;
		--n;
		if (0 == n)
		{
			string::size_type pos = bignum.find_first_not_of('0');
			cout << bignum.substr(pos) << endl;
			continue;
		}
		
		vector<unsigned> sum(bignum.size(), 0U);
		for (string::size_type i = 0, size = bignum.size(); i < size; ++i)
			sum[i] = bignum[size - i - 1] - '0';		
		
		while (n--)
		{
			cin >> bignum;			
			string::size_type num_size = bignum.size(), sum_size=sum.size();
			string::size_type min_size(num_size < sum_size ? num_size : sum_size);
				unsigned carry = 0;
			string::size_type i = 0;
			while (i < min_size)
			{
				unsigned result = carry + sum[i] + bignum[num_size - i - 1] - '0';
				sum[i] = result % 10;
				carry = result / 10;
				++i;
			}
			if(min_size==num_size)
			{
				while(i<sum_size)
				{
					unsigned result = carry + sum[i];
					sum[i] = result % 10;
					carry = result / 10;
					++i;
				}			
			}
			else
			{
				while(i<num_size)
				{
					unsigned result = carry + bignum[num_size - i - 1]-'0';
					sum.push_back(result % 10) ;
					carry = result / 10;
					++i;
				}
			}
			if(carry)
					sum.push_back(carry);	
		}
		vector<unsigned>::reverse_iterator it = find_if(sum.rbegin(),
			sum.rend(),
			bind2nd(not_equal_to<unsigned>(),
			0));
		for (; it != sum.rend(); ++it)
			cout << *it;
		cout << endl;
	}
	
	return 0;
}

